//
//  CashListController.m
//  Ten
//
//  Created by anfuer on 2018/8/18.
//  Copyright © 2018年 xg韦. All rights reserved.
//

#import "CashListController.h"
#import "CashCell.h"
#import "ZfbbkViewController.h"
#import "GetcashViewController.h"
@interface CashListController ()
{
    NSArray*dataary;
    NSDictionary*dict;
}
@property (weak, nonatomic) IBOutlet UITableView *tbv;

@end

@implementation CashListController
- (IBAction)addBankBtna:(UIButton *)sender {
    [MyUtils collviewSelidex:@"绑定银行卡" toVc:self andShopInfo:nil];
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:NO];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
    [FuncPublic getData:self parameters:nil RequestUrl:Cget_bind_info success:^(NSDictionary *acountInfo) {
        dict=acountInfo;
        [self loaddat];

    }];
    
}

-(void)loaddat
{
    [FuncPublic getData:self parameters:nil RequestUrl:salarybankcards success:^(NSDictionary *acountInfo) {
        if ([[acountInfo allKeys]containsObject:@"list"]) {
            NSArray*tempary=acountInfo[@"list"];
            dataary=@[@[@"微信",@"支付宝"],tempary];
        }else
        {
            dataary=@[@[@"微信",@"支付宝"]];
        }
        [_tbv reloadData];
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
      _tbv.separatorColor=[UIColor clearColor];

    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark 返回分组数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return dataary.count;
}

#pragma mark 返回每组行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray*tempary=dataary[section];
    return  tempary.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    NSString*str= indexPath.section==0? dataary[indexPath.section][indexPath.row]:dataary[indexPath.section][indexPath.row][@"bank_name"];
    static NSString *ID = @"CashCell";
    CashCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.img.image=WXGImage(str);
    cell.lb1.text=str;
    if (indexPath.section==0) cell.contentView.alpha=0.5;
    return cell;
}
#pragma mark 设置分组头高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}


#pragma mark 设置尾部说明内容高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

#pragma mark 设置每行高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}
#pragma mark 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
     if (indexPath.section==0) {
          [WSProgressHUD showImage:nil status:@"系统暂只支持银行卡提现"];
          return;
     }
    
    if (indexPath.section==0) {
        NSString*str=dataary[indexPath.section][indexPath.row];
        if ([str isEqualToString:@"微信"]) {
            
            if (![[dict allKeys]containsObject:@"wx_account"]||[WXGStr(dict[@"wx_account"])empty]) {
                //去绑卡
                UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"bk" bundle:nil];
                ZfbbkViewController*secondViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"ZfbbkView"];
                secondViewController.type=@"wx";
                [self.navigationController pushViewController:secondViewController animated:YES];
            }else
            {
                //去提现
                UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"shop" bundle:nil];
                GetcashViewController*secondViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"Getcash"];
                secondViewController.passdic=dict;
                [self.navigationController pushViewController:secondViewController animated:YES];
            }
            
            
        }else if ([str isEqualToString:@"支付宝"]||[WXGStr(dict[@"alipay_account"])empty])
        {
            if (![[dict allKeys]containsObject:@"alipay_account"]) {
                UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"bk" bundle:nil];
                UIViewController*secondViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"ZfbbkView"];
                [self.navigationController pushViewController:secondViewController animated:YES];
            }else
            {
                //去提现
                UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"shop" bundle:nil];
                GetcashViewController*secondViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"Getcash"];
                secondViewController.type=@"zfb";
                secondViewController.passdic=dict;
                [self.navigationController pushViewController:secondViewController animated:YES];
                
            }
        }
    }else
    {
         NSMutableDictionary*mdic= [NSMutableDictionary dictionaryWithDictionary:dataary[indexPath.section][indexPath.row]];
        [mdic addEntriesFromDictionary:dict];
        UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"shop" bundle:nil];
        GetcashViewController*secondViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"Getcash"];
        secondViewController.type=@"Bank";
        secondViewController.passdic=mdic;
        [self.navigationController pushViewController:secondViewController animated:YES];
    }
    
  
    
}

@end
